package class_wuziqi;

import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.List;

public class ServerReceive implements Runnable{
	private Socket socket;
	private List<Socket> socket_list;
	private	ChatRecord<String> chatRecord;
	
	public ServerReceive(Socket socket, List<Socket> socket_list,ChatRecord<String> chatRecord) {
		this.socket = socket;
		this.socket_list = socket_list;
		this.chatRecord = chatRecord;
	}

	@Override
	public void run() {
		try {
			while(true){
				ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
				String a=(String)ois.readObject();
				chatRecord.add(socket.getInetAddress()+"说："+a+"\n");				
			}
		} catch (Exception e) {
			socket_list.remove(socket);
			chatRecord.add(socket.getInetAddress()+"离开了");
		}
	}

}
